package role

import (
	"parking-lot-go-admin/controller"
	"parking-lot-go-admin/model"
	"parking-lot-go-admin/model/admin"
	"strconv"
	"strings"

	"github.com/gin-gonic/gin"
)

func UpdateGroup(c *gin.Context) {

	requestDataStruct := struct {
		Id    int   `json:"id"`
		Rules []int `json:"rules"`
	}{}

	c.ShouldBindJSON(&requestDataStruct)

	ruleStringSlice := make([]string, len(requestDataStruct.Rules))
	for i, num := range requestDataStruct.Rules {
		ruleStringSlice[i] = strconv.Itoa(num)
	}

	//查询信息
	var adminGroupStruct admin.AdminGroupStruct
	model.UpdateModelData(
		model.Db,
		adminGroupStruct.TableName(),
		map[string]interface{}{
			"id": requestDataStruct.Id,
		},
		map[string]interface{}{
			"rules": strings.Join(ruleStringSlice, ","),
		},
	)

	controller.Success(c, "")
}
